package com.zy.xuanwo.utils;

import android.content.Context;
import android.support.annotation.StringRes;
import android.widget.Toast;

import com.zy.xuanwo.application.MyApplication;


/**
 * Created by njb on 2015/1/4.
 */

public class ToastUtils {

    //通过Application获取全局Context
    private static Context context = MyApplication.getContext();


    private ToastUtils() {
            /* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    public static boolean isShow = true;

    /**
     * 短时间显示Toast
     *
     * @param message
     */
    public static void showShort(CharSequence message) {
        if (isShow)
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    /**
     * 短时间显示Toast
     *
     * @param resId
     */
    public static void showShort(@StringRes int resId) {
        if (isShow)
            Toast.makeText(context, context.getResources().getText(resId), Toast.LENGTH_SHORT).show();
    }

    /**
     * 长时间显示Toast
     *
     * @param message
     */
    public static void showLong(CharSequence message) {
        if (isShow)
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }

    /**
     * 长时间显示Toast
     *
     * @param resId
     */
    public static void showLong(@StringRes int resId) {
        if (isShow)
            Toast.makeText(context, context.getResources().getText(resId), Toast.LENGTH_LONG).show();
    }

    /**
     * 自定义显示Toast时间
     *
     * @param message
     * @param duration
     */
    public static void show(CharSequence message, int duration) {
        if (isShow)
            Toast.makeText(context, message, duration).show();
    }

    /**
     * 自定义显示Toast时间
     *
     * @param message
     * @param duration
     */
    public static void show( int message, int duration) {
        if (isShow)
            Toast.makeText(context, message, duration).show();
    }

}